
#ifndef _PROJECTZ_NUSER_NCOMMAND_CS_REQ_SOCIAL_INFO_H_
#define _PROJECTZ_NUSER_NCOMMAND_CS_REQ_SOCIAL_INFO_H_

#include "../../User.h"
#include "../../NLogic/Equip.h"
#include "../../NLogic/Item.h"
#include "../../NLogic/SocialInfo.h"


namespace ProjectZ { namespace NCommand { namespace NWorld {


class CS_REQ_SOCIAL_INFO
{
public:
	static void OnExecute(User * pUser, ::Network::Packet * pPacket)
	{
//		//소셜 정보 요청
//		CS_REQ_SOCIAL_INFO		0x0941
//		{
//			u32	 u32gid;
//		}
//
//		SC_REQ_SOCIAL_INFO		0x0942
//		{
//			u32	u32gid;							///gid
//			str struser_id;						/// 카카오톡 사용자 아이디(GUID)  login ID 17자리
//			str struser_nickname;				/// 카카오톡 사용자 닉네임.
//			str struser_profile_image_url;		/// 카카오톡 프로필 이미지 URL
//			u16	u16Level;						///레벨
//
//			u8	u8class;						/// 클래스
//
//			u8	u8costume_head;					/// 기본 코스튬 정보
//			u8	u8costume_armor;
//			u8	u8costume_weapon;
//			u8	u8costume_side_hand;
//			u8	u8costume_effect;
//
//			s16	s16pet_tid;						//전투펫 TID (-1: 없음)
//		}


		STRESSLOG("CS_REQ_SOCIAL_INFO");

		NLogic::Space * pSpace = pUser->GetSpace();
		if (NULL == pSpace)
		{
			DEBUGLOG("CS_REQ_SOCIAL_INFO pSpace is NULL");
			return;
		}

		if (true == pSpace->IsSingleDungeon())
		{
			DEBUGLOG("CS_REQ_SOCIAL_INFO pSpace->GetData()._spaceType == NLogic::Space::SpaceType::SINGLE_DUNGEION");
			return;
		}

		PREPARE_PACKET;

		int userSeq	= 0;
		* pPacket >> userSeq;

		User * pOppUser = NULL;

		if (pUser->GetEnumState() == User::EnumState::PVP_QUICK_WAIT
				|| pUser->GetEnumState() == User::EnumState::PVP_AMITY_WAIT
				|| pUser->GetEnumState() == User::EnumState::PVP_FRIENDLY_WAIT)
		{
			NLogic::Party * pParty = pUser->GetParty();
			if (NULL == pSpace)
			{
				DEBUGLOG("CS_REQ_SOCIAL_INFO pParty is NULL");
				return;
			}

//			auto iter = pParty->GetAllUserTree().begin();
//			for ( ; iter != pParty->GetAllUserTree().end(); iter++)
//			{
//				if (iter->second == pUser)
//					continue;
//
//				pOppUser = iter->second;
//				break;
//			}
			pOppUser = pParty->FindAllUser(userSeq);
		}
		else if (pUser->GetEnumState() == User::EnumState::BATTLE_ROYAL_PARTY_WAIT)
		{
			pOppUser = pUser->GetParty()->FindAllUser(userSeq);
		}
		else if (pSpace->GetData()._spaceType == NLogic::Space::SpaceType::WORLD && NULL != pUser->GetParty())
		{
			pOppUser = pUser->GetParty()->FindAllUser(userSeq);
		}
		else if (true == pSpace->IsPartyDungeon() || pSpace->GetData()._spaceType == NLogic::Space::SpaceType::WORLD)
		{
			pOppUser = pSpace->FindUser(userSeq);
		}
		else
		{
			return;
		}


		if (pOppUser == NULL)
		{
			DEBUGLOG("CS_REQ_SOCIAL_INFO %d pOppUser[%d] == NULL", __LINE__, userSeq);
			return;
		}

		NLogic::Equip * pEquip = pOppUser->GetEquip();
		if (NULL == pEquip)
		{
			DEBUGLOG("CS_REQ_SOCIAL_INFO : pEquip is NULL!!!");
			return;
		}

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

		*pAck << userSeq;
		*pAck << pOppUser->GetSocialID().c_str();

		if(1 == pOppUser->GetSocialInfo()->GetData()->_profile_opened)
		{
			*pAck << pOppUser->GetUserInfo().nickname.c_str();
			*pAck << pOppUser->GetUserInfo().profile_url.c_str();
		}
		else
		{
			*pAck << static_cast<uint16_t>(0);
			*pAck << static_cast<uint16_t>(0);
		}

		*pAck << static_cast<uint16_t>(pOppUser->GetCharacterInfo().level);
		*pAck << static_cast<uint8_t>(pOppUser->GetCharacterInfo().classtype);

		// 아바타를 장착한 경우
		if (true == pEquip->IsExistItem(ITEM_EQUIP_POS_AVARTAR))
		{
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		}
		else
		{
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_HELMET));
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_ARMOR));
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_WEAPON));
			*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_WEAPON));
		}

		*pAck << static_cast<uint8_t>(0);

		NLogic::Item * pItem = pEquip->GetItem(ITEM_EQUIP_POS_PET);
		if (pItem == NULL)
			*pAck << static_cast<int16_t>(-1);
		else
			*pAck << static_cast<int16_t>(pItem->GetData().tid);

		pAck->MakePacket(CMD_SC_REQ_SOCIAL_INFO);
		pUser->Send(pAck);
	}
};

} /*NWorld*/ } /*NCommand*/ } /*ProjectZ*/

#endif /* _PROJECTZ_NUSER_NCOMMAND_CS_REQ_SOCIAL_INFO_H_ */
